<?php
/**
 * @Author    紫梦
 * @DateTime  2018-02-09
 * @copyright 响响租车
 * @license   [license]
 * @version   1.0
 * @param     string     $value [description]
 */
namespace app\wxapp\controller;
use app\common\model\Cars;
use app\common\controller\OperateTemp as Action;

class Operate extends Basic
{
    
    public function index($id)
    {
        $this->assign('id',$id);
        return $this->fetch();
    }

    public function unlock($id)
    {
        $model = Cars::get($id);

        if($model['supplier_no'] == 1376920002){

            $config = config('gz_blt');

            $url = rtrim($config['url'],'/').'/api/vehicle/doCommandAction';

            return Action::operation($config,$model['car_unique_id'],'LOCK',1,$url);

        }elseif ($model['supplier_no'] == 1376920003) {

            $config = config('local_iot');

            $url = rtrim($config['url'],'/').'/command/doCommandAction';

            return Action::operation($config,$model['car_unique_id'],'LOCK',1,$url);
        }
    }

    public function lock($id)
    {
        $model = Cars::get($id);

        if($model['supplier_no'] == 1376920002){

            $config = config('gz_blt');

            $url = rtrim($config['url'],'/').'/api/vehicle/doCommandAction';

            return Action::operation($config,$model['car_unique_id'],'LOCK',0,$url);

        }elseif ($model['supplier_no'] == 1376920003) {

            $config = config('local_iot');

            $url = rtrim($config['url'],'/').'/command/doCommandAction';

            return Action::operation($config,$model['car_unique_id'],'LOCK',0,$url);
        }
    }

    public function ignite($id)
    {
        $model = Cars::get($id);

        if($model['supplier_no'] == 1376920002){

            $config = config('gz_blt');

            $url = rtrim($config['url'],'/').'/api/vehicle/doCommandAction';

            return Action::operation($config,$model['car_unique_id'],'IGNITE',1,$url);

        }elseif ($model['supplier_no'] == 1376920003) {

            $config = config('local_iot');

            $url = rtrim($config['url'],'/').'/command/doCommandAction';

            return Action::operation($config,$model['car_unique_id'],'IGNITE',1,$url);
        }
    }

    public function unignite($id)
    {
        $model = Cars::get($id);
        
        if($model['supplier_no'] == 1376920002){

            $config = config('gz_blt');

            $url = rtrim($config['url'],'/').'/api/vehicle/doCommandAction';

            return Action::operation($config,$model['car_unique_id'],'IGNITE',0,$url);

        }elseif ($model['supplier_no'] == 1376920003) {

            $config = config('local_iot');

            $url = rtrim($config['url'],'/').'/command/doCommandAction';

            return Action::operation($config,$model['car_unique_id'],'IGNITE',0,$url);
        }
    }


    public function whistle($id)
    {
        $model = Cars::get($id);
        
        if($model['supplier_no'] == 1376920002){

            $config = config('gz_blt');

            $url = rtrim($config['url'],'/').'/api/vehicle/doCommandAction';

            return Action::operation($config,$model['car_unique_id'],'WHISTLE',1,$url);

        }elseif ($model['supplier_no'] == 1376920003) {

            $config = config('local_iot');

            $url = rtrim($config['url'],'/').'/command/doCommandAction';

            return Action::operation($config,$model['car_unique_id'],'WHISTLE',1,$url);
        }
    }
}